<template>
    <div class="content">
        <Collapse v-model="value2">
          <Panel name="1">
              常规设置
              <div slot="content">
                  <Form  label-position="right" :label-width="100">
                        <div class="canshu">
                            <FormItem label="">
                            <Input class="w80" v-model="wenjian.configBtc.lessDayPrincipalFee" /> 层
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="keppout(wenjian.configBtc.id,wenjian.configBtc.lessDayPrincipalFee,wenjian.configBtc.lessDayIncomeFee,wenjian.configBtc.day,wenjian.configBtc.greaterDayPrincipalFee,wenjian.configBtc.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>
                        <div class="canshu">
                            <FormItem label="抽取：">
                             <Input class="w80" v-model="wenjian.configEth.lessDayPrincipalFee" /> % 
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="keppout(wenjian.configEth.id,wenjian.configEth.lessDayPrincipalFee,wenjian.configEth.lessDayIncomeFee,wenjian.configEth.day,wenjian.configEth.greaterDayPrincipalFee,wenjian.configEth.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>

                        <div class="canshu">
                            <FormItem label="间隔时间：">
                             <Input class="w80" v-model="wenjian.configEth.lessDayPrincipalFee" /> 天
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="keppout(wenjian.configEth.id,wenjian.configEth.lessDayPrincipalFee,wenjian.configEth.lessDayIncomeFee,wenjian.configEth.day,wenjian.configEth.greaterDayPrincipalFee,wenjian.configEth.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>
                        <div class="canshu">
                            <FormItem label="已推荐">
                             <Input class="w80" v-model="wenjian.configEth.lessDayPrincipalFee" /> 位广告主
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="keppout(wenjian.configEth.id,wenjian.configEth.lessDayPrincipalFee,wenjian.configEth.lessDayIncomeFee,wenjian.configEth.day,wenjian.configEth.greaterDayPrincipalFee,wenjian.configEth.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>

                        
                  </Form>
              </div>
          </Panel>
          
      </Collapse>
    </div>

</template>
<script>
export default {
  data () {
    return {
      wenjian: {}, // 稳健基金
      value2: '1',
      btcincomeNum: '',
      ethincomeNum: ''

    }
  },
  methods: {
    // 查询稳健基金参数
    getWenjian () {
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('parameter/fund/config', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.wenjian = res.data.data
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 添加btc收益等级
    addbtc (incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        incomeNum: incomeNum
      })
      this.axios
        .post('parameter/fund/btcgrade', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.getWenjian()
            this.$Message.info(res.data.message)
            this.btcincomeNum = null
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 删除btc推荐收益等级
    delbtc (id) {
      let token = localStorage.getItem('mytoken')
      this.axios.delete('parameter/fund/btcgrade/' + id, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改btc推荐收益等级
    keppbtc (id,incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        incomeNum: incomeNum
      })
      this.axios.put('parameter/fund/btcgrade', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 添加eth收益等级
    addeth (incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        incomeNum: incomeNum
      })
      this.axios
        .post('parameter/fund/ethgrade', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.getWenjian()
            this.$Message.info(res.data.message)
            this.ethincomeNum = null
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 删除eth推荐收益等级
    deleth (id) {
      let token = localStorage.getItem('mytoken')
      this.axios.delete('parameter/fund/ethgrade/' + id, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改eth推荐收益等级
    keppeth (id,incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        incomeNum: incomeNum
      })
      this.axios.put('parameter/fund/ethgrade', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },

    // 修改稳健基金退出机制
    keppout (id, lessDayPrincipalFee, lessDayIncomeFee, day, greaterDayPrincipalFee, greaterDayIncomeFee) {
      let reg = /[^\d^\.]+/g
      if (lessDayPrincipalFee === '') {
        this.$Message.info('最低本金不能为空')
        return false
      }
      if (lessDayIncomeFee === '') {
        this.$Message.info('最低收益不能为空')
        return false
      }
      if (day === '') {
        this.$Message.info('天数不能为空')
        return false
      }
      if (greaterDayPrincipalFee === '') {
        this.$Message.info('最高本金不能为空')
        return false
      }
      if (greaterDayIncomeFee === '') {
        this.$Message.info('最高收益不能为空')
        return false
      }

      let wj1 = reg.test(lessDayPrincipalFee)
      if (wj1) {
        this.$Message.info('请输入正数')
        return false
      }
      let wj2 = reg.test(lessDayIncomeFee)
      if (wj2) {
        this.$Message.info('请输入正数')
        return false
      }
      let wj3 = reg.test(day)
      if (wj3) {
        this.$Message.info('请输入正数')
        return false
      }
      let wj4 = reg.test(greaterDayPrincipalFee)
      if (wj4) {
        this.$Message.info('请输入正数')
        return false
      }
      let wj5 = reg.test(greaterDayIncomeFee)
      if (wj5) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        greaterDayPrincipalFee: greaterDayPrincipalFee,
        greaterDayIncomeFee: greaterDayIncomeFee,
        day: day,
        lessDayPrincipalFee: lessDayPrincipalFee,
        lessDayIncomeFee: lessDayIncomeFee
      })

      this.axios.put('parameter/fund/config', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改稳健基金日封顶
    keppcaps (id, caps) {
      let reg = /[^\d^\.]+/g
      if (caps === '') {
        this.$Message.info('日收益封顶不能为空')
        return false
      }
      let wj = reg.test(caps)
      if (wj) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        caps: caps
      })

      this.axios.put('parameter/fund/config', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getWenjian()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    }

  },
  created () {
    this.getWenjian()
  },
  mounted () {
    this.$Message.config({
      top: 250
    })
  }
}
</script>
<style lang="less" scoped>
.p-10 {
  padding-top: 0 !important;
  padding-left: 50px !important;
}
.w50 {
  width: 50px !important;
}
.mar {
  margin-left: 5px;
}
</style>
